package cn.itcast.activiti.servlet.history;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricProcessInstanceQuery;

import cn.itcast.activiti.common.ProcessEngineUtils;
/**
 * 查询历史流程定义实例
 * @author Administrator
 *
 */
@WebServlet("/queryHistoryProcessDefinitionInstance.action")
public class QueryHistoryProcessDefinitionInstanceServlet extends HttpServlet{

	private static final long serialVersionUID = -7472394676233189500L;
	
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			//获取流程引擎
			ProcessEngine processEngine=ProcessEngineUtils.getProcessEngine();
			//获取历史服务
			HistoryService historyService=processEngine.getHistoryService();
			//创建历史流程实例查询对象
			HistoricProcessInstanceQuery historicProcessInstanceQuery=historyService.createHistoricProcessInstanceQuery();
			
			/** 调用HistoricProcessInstanceQuery中方法完成查询 */// finished()已完成的
			List<HistoricProcessInstance> hpilist=historicProcessInstanceQuery.finished().orderByProcessInstanceStartTime().asc().list();
			request.setAttribute("hpilist", hpilist);
			
			request.getRequestDispatcher("/historyProcessInstance.jsp").forward(request, response);
	}

}
